package com.yonyou.common.service.messagecenter.util;

import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.yonyou.common.service.messagecenter.config.RabbitMQConfig;

@Component
public class FixedQueue {
    @Autowired
    private RabbitMQConfig config;
    
	private ConcurrentLinkedQueue<Long> counts=new ConcurrentLinkedQueue<Long>();
	public void add(){
		long t=System.currentTimeMillis();
		counts.offer(t);
//		if(counts.size()>=config.getFixqueueQty()+1){
//			counts.poll();
//		}
	}
	public void clear(){
		counts.clear();
	}
	//计算每秒请求数
	public double getPerNumber(){
		Object[] s=counts.toArray();
		int l=s.length;
		if(l==0)
			return 0;
 		double t1=(double)s[0];
 		double t2=(double)s[l-1];
 		double dif=t2-t1;
 		if(dif==0) dif=1;
 		double tmp=(double)(1000*l);
 		double k=tmp/dif;
		return k;
	}
}
